unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids, DBGrids, DB, DBClient;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit2: TEdit;
    Memo1: TMemo;
    Edit3: TEdit;
    Button2: TButton;
    DBGrid1: TDBGrid;
    DataSource1: TDataSource;
    ClientDataSet1: TClientDataSet;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
    FToken : String;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
uses DataJK,uLkJSON,ZLibCompress;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  S1 : Service1Soap;
  sText : string;
  js : TlkJSONbase;
begin
  S1 := GetService1Soap(False,Edit3.Text);
  sText := S1.Login('75896479C55D33C0','A35F651A668A04C2');

  Memo1.Lines.Add(sText);
  sText := UTF8Encode(sText);
  js := TlkJSON.ParseText(sText);
  Memo1.Lines.Add(TlkJSONstring(js.Field['Code']).Value);
  Memo1.Lines.Add(TlkJSONstring(js.Field['Message']).Value);
  Memo1.Lines.Add(TlkJSONstring(js.Field['Result']).Value);

  FToken := TlkJSONstring(js.Field['Result']).Value;
  //TlkJSON

end;

procedure TForm1.Button2Click(Sender: TObject);
var
  S1 : Service1Soap;
  sText,sCode,sMsg,sSql : string;

  js : TlkJSONbase;
begin
  Memo1.Lines.Add(FormatDateTime('hh:nn:zzz',Now));
  S1 := GetService1Soap(False,Edit3.Text);

  //eNorTs1JTS5R0FJIK8rPVXAMjnfx8Yn38QwOAQBuNggp
  sSql := Edit2.Text;
  sSql := CompressStr(sSql);
  sText := S1.Query(sSql,FToken);
//  Memo1.Lines.Add(sText);
  Memo1.Lines.Add(FormatDateTime('hh:nn:zzz',Now));
  sText := UTF8Encode(sText);
  js := TlkJSON.ParseText(sText);
//  Memo1.Lines.Add(TlkJSONstring(js.Field['Code']).Value);
//  Memo1.Lines.Add(TlkJSONstring(js.Field['Message']).Value);
//  Memo1.Lines.Add(TlkJSONstring(js.Field['Result']).Value);
  sCode := TlkJSONstring(js.Field['Code']).Value;
  if (sCode = '1') then
  begin
    sText := TlkJSONstring(js.Field['Result']).Value;
    Memo1.Lines.Add(FormatDateTime('hh:nn:zzz',Now));
    sText := DeCompressStr(sText);
  //  Memo1.Lines.Add(sText);
    Memo1.Lines.Add(FormatDateTime('hh:nn:zzz',Now));
    ClientDataSet1.XMLData := sText;
    Memo1.Lines.Add(FormatDateTime('hh:nn:zzz',Now));
  end
  else
  begin
    sMsg := TlkJSONstring(js.Field['Message']).Value;
    Memo1.Lines.Add(sMsg);

  end;
end;

end.
